package com.hzpd.hainan.module.news.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hzpd.hainan.R;
import com.hzpd.hainan.app.ListBaseAdapter;
import com.hzpd.hainan.model.news.SearchHisBean;
import com.hzpd.hainan.utils.ViewHolder;

import org.litepal.crud.DataSupport;

/**
 * Created by 猪猪侠 on 2017/7/6.
 */
public class SearchRecordAdapter extends ListBaseAdapter<SearchHisBean> {


    public SearchRecordAdapter(Activity context) {
        super(context);
    }

    @Override
    public View getMyView(int position, View convertView, ViewGroup parent) {
        if (null == convertView) {
            convertView = inflater.inflate(R.layout.search_record_item, parent, false);
        }
        final String content = list.get(position).getContent();
        final int p = position;
        TextView tv = ViewHolder.get(convertView, R.id.keyword_tv);
        RelativeLayout cancel_rl = ViewHolder.get(convertView, R.id.delete_bt);
        tv.setText(list.get(position).getContent());
        cancel_rl.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
//                searchTask.deleteKeyword(content);
                DataSupport.deleteAll(SearchHisBean.class,"content=?",content);
                list.remove(p);
                notifyDataSetChanged();
            }
        });
        return convertView;
    }
}
